(require readline/readline)

(define line "")

(define (next-char)
  (if (> (string-length line) 0)
    (let ((c (string-ref line 0)))
      (set! line (substring line 1))
      c)
    #\space))

(define (char-alphanumeric? c)
  (or (char-alphabetic? c) (char-numeric? c)))

(define (next-token)
  (set! line (string-trim line))
  (if (equal? line "")
    (begin (set! line (readline ">:"))
           (next-token))
    (let ((c (next-char)))
      (cond ((member c (string->list "(){}|+-*/:><="))
             (case c
               ((#\()
                (values 'left-paren (string c)))
               ((#\))
                (values 'right-paren (string c)))
               ((#\{)
                (values 'left-curly (string c)))
               ((#\})
                (values 'right-curly (string c)))
               ((#\+)
                (values 'plus (string c)))
               ((#\-)
                (values 'minus (string c)))
               ((#\*)
                (values 'times (string c)))
               ((#\/)
                (values 'divide (string c)))
               ((#\:)
                (set! c (next-char))
                (if (eq? c #\=)
                  (values 'assign ":=")
                  (values 'unknown (string-append ":" (string c)))))
               ((#\>)
                (set!
                
                
            ; symbol token
            ((char-upper-case? c)     
             (do ((t (string c) (string-append t (if (char-alphanumeric? c)
                                                   (string c)
                                                   ""))))
               ((not (char-alphanumeric? c))
                (values 'symbol (string->symbol t)))
               (set! c (next-char))))
            ; 
            ((char-lower-case? c)
             (do ((t (string c) (string-append t (if (char-alphanumeric? c)
                                                   (string c)
                                                   ""))))
               ((not (char-alphanumeric? c))
                (values (id-type t) t))
               (set! c (next-char))))
            ; number token
            ;((or (eq? c #\~) (char-numeric? c))
            ; (let ((sign (if (eq? c #\~) -1 1))
            ;       (ipart (string c))
            ;       (fpart "")
            ;       (epart ""))
            ;   (do ()
            ;       (
            (else (values 'unknown #f)))
            
             
    
